/**
 * 
 */
package org.mechanic.exception;

import org.mechanic.core.web.HttpStatusCode;
import org.springframework.ui.ModelMap;


public abstract class BaseException extends RuntimeException {
	
	protected HttpStatusCode httpStatusCode;
	
	public BaseException() {
	}

	public BaseException(Throwable ex) {
		super(ex);
	}

	public BaseException(String message) {
		super(message);
	}

	public BaseException(String message, Throwable ex) {
		super(message, ex);
	}
	
	public BaseException(HttpStatusCode httpStatusCode, Throwable ex) {
		super(httpStatusCode.message(), ex);
		this.httpStatusCode = httpStatusCode;
	}
	
	public BaseException(HttpStatusCode httpStatusCode) {
		super(httpStatusCode.message());
		this.httpStatusCode = httpStatusCode;
	}

	public void handler(ModelMap modelMap) {
		HttpStatusCode httpStatusCode = (this.httpStatusCode==null)?getHttpStatusCode():this.httpStatusCode;
		modelMap.put("code", httpStatusCode.value());
		modelMap.put("message", httpStatusCode.message());
		modelMap.put("timestamp", System.currentTimeMillis());
	}

	protected abstract HttpStatusCode getHttpStatusCode();
}
